package com.cmc.cloud.cmclink.doc.controller.admin;

import cn.hutool.core.bean.BeanUtil;
import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.vo.voyagebookingtimevo.VoyageBookingTimeCreateReqVO;
import com.cmc.cloud.cmclink.doc.vo.voyagebookingtimevo.VoyageBookingTimePageReqVO;
import com.cmc.cloud.cmclink.doc.vo.voyagebookingtimevo.VoyageBookingTimeQueryVO;
import com.cmc.cloud.cmclink.doc.vo.voyagebookingtimevo.VoyageBookingTimeRespVO;
import com.cmc.cloud.cmclink.doc.vo.voyagebookingtimevo.VoyageBookingTimeUpdateReqVO;
import com.cmes.framework.biz.advice.annotations.UseResponsePropertyAdvice;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.common.pojo.PageResult;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import java.util.*;


import com.cmc.cloud.cmclink.doc.entity.VoyageBookingTimeDO;
import com.cmc.cloud.cmclink.doc.service.VoyageBookingTimeService;


/**
 * 航次截止时间前端接口Controller
 *
 * @author codegen
 */
@Tag(name = "管理后台 - 航次截止时间")
@RestController
@Validated
@RequestMapping(UrlConstants.APPLICATION_URL + "/bookingTime")
public class VoyageBookingTimeController {

    @Resource
    private VoyageBookingTimeService voyageBookingTimeService;

    @Operation(summary = "创建航次截止时间")
    @PostMapping("/create")
    public CommonResult<Void> createVoyageBookingTime(@Valid @RequestBody VoyageBookingTimeCreateReqVO createReqVO) {
        voyageBookingTimeService.createVoyageBookingTime(createReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "更新航次截止时间")
    @PostMapping("/update")
    public CommonResult<Void> updateVoyageBookingTime(@Valid @RequestBody VoyageBookingTimeUpdateReqVO updateReqVO) {
        voyageBookingTimeService.updateVoyageBookingTime(updateReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "删除航次截止时间")
    @PostMapping("/delete/{id}")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Void> deleteVoyageBookingTime(@PathVariable("id") Long id) {
        voyageBookingTimeService.deleteVoyageBookingTime(id);
        return CommonResult.success();
    }

    @Operation(summary = "获得航次截止时间")
    @GetMapping("/get/{id}")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<VoyageBookingTimeRespVO> getVoyageBookingTime(@PathVariable("id") Long id) {
        VoyageBookingTimeDO voyageBookingTime = voyageBookingTimeService.getVoyageBookingTime(id);
        return CommonResult.success(BeanUtil.copyProperties(voyageBookingTime, VoyageBookingTimeRespVO.class));
    }

    @Operation(summary = "获得航次截止时间列表")
    @GetMapping("/list")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    public CommonResult<List<VoyageBookingTimeRespVO>> getVoyageBookingTimeList(@RequestParam("ids") Collection<Long> ids) {
        List<VoyageBookingTimeDO> list = voyageBookingTimeService.getVoyageBookingTimeList(ids);
        return CommonResult.success(BeanUtil.copyToList(list, VoyageBookingTimeRespVO.class));
    }

    @Operation(summary = "获得航次截止时间分页")
    @PostMapping("/page")
    @UseResponsePropertyAdvice
    public CommonResult<PageResult<VoyageBookingTimeRespVO>> getVoyageBookingTimePage(@Valid @RequestBody VoyageBookingTimePageReqVO pageVO) {
        PageResult<VoyageBookingTimeDO> pageResult = voyageBookingTimeService.getVoyageBookingTimePage(pageVO);
        List<VoyageBookingTimeRespVO> results = BeanUtil.copyToList(pageResult.getList(), VoyageBookingTimeRespVO.class);
        return CommonResult.success(new PageResult<>(results, pageResult.getTotal()));
    }

    @Operation(summary = "不分页获得航次截止时间")
    @PostMapping("/query")
    @UseResponsePropertyAdvice
    public CommonResult<List<VoyageBookingTimeRespVO>> queryVoyageBookingTime(@Valid @RequestBody VoyageBookingTimeQueryVO bookingTimeQueryVO) {
        List<VoyageBookingTimeRespVO> results = voyageBookingTimeService.queryVoyageBookingTime(bookingTimeQueryVO);
        return CommonResult.success(results);
    }
}
